Skip to content

Phase 7 Step 3d (leaf 2/5): thread config into write-security [stacked on #19]#20

Closed
ethanj wants to merge 1 commit intophase7-3d-consensus-extractionfrom
phase7-3d-write-security
Closed

Phase 7 Step 3d (leaf 2/5): thread config into write-security [stacked on #19]#20
ethanj wants to merge 1 commit intophase7-3d-consensus-extractionfrom
phase7-3d-write-security

Conversation

@ethanj
Copy link
Copy Markdown
Contributor

@ethanj ethanj commented Apr 18, 2026

Stacked PR — based on #19. Review #19 first; merge #19 before this one. GitHub will auto-update the base to architecture2 when #19 merges.

Summary

Phase 7 Step 3d leaf 2/5 — thread config explicitly through write-security.ts instead of reading the module singleton. Second drop in the MAX_SINGLETON_IMPORTS ratcheting sequence: 32 → 31.

Plan: atomicmemory-research/docs/core-repo/rearchitecture/phase7-v1-parity/phase7plan.md Item 3d.

What changed

  • src/services/write-security.ts — dropped the import { config } binding. Both exported functions take config explicitly:
    • assessWriteSecurity(content, sourceSite, WriteSecurityAssessConfig) — reads trustScoringEnabled, trustScoreMinThreshold.
    • recordRejectedWrite(userId, content, sourceSite, decision, WriteSecurityRecordConfig, lessons?) — reads auditLoggingEnabled, lessonsEnabled, trustScoreMinThreshold. The last is used to rebuild the trust:below-threshold audit payload — preserved from v1 behavior.
    • Two new exported config interfaces, both Pick-style.
  • src/services/memory-ingest.ts + src/services/ingest-fact-pipeline.ts — all 6 call sites thread deps.config. No signature ripple upstream; every caller already had deps in scope.
  • src/services/memory-service-types.tsIngestRuntimeConfig gains trustScoringEnabled and trustScoreMinThreshold so deps.config satisfies both new config interfaces structurally.
  • src/services/__tests__/write-security.test.ts — stopped importing and mutating the config singleton in tests. Each test builds its own WriteSecurityAssessConfig explicitly. Pure unit tests now, no module-level side effects.
  • src/__tests__/config-singleton-audit.test.tsMAX_SINGLETON_IMPORTS ratcheted 32 → 31.

Behavior preservation

The v1 audit event trust:below-threshold included a threshold field populated from config.trustScoreMinThreshold. Dropping the singleton import required threading the threshold into recordRejectedWrite so the payload can still be emitted. WriteSecurityRecordConfig.trustScoreMinThreshold exists specifically for this.

Test plan

  • npx tsc --noEmit clean
  • npm test 963/963 pass
  • fallow --no-cache 0 above threshold
  • config-singleton-audit.test.ts passes at new threshold 31
  • write-security.test.ts rewritten to not depend on singleton mutation; all 3 cases still pass
  • Upstream mock-based tests (memory-ingest-runtime-config.test.ts, ingest-fact-pipeline-workspace.test.ts) unchanged — their mocks accept the extra arg implicitly

Out of scope

  • Three leaves remain in the ratcheting sequence: cost-telemetry.ts, embedding.ts, llm.ts.

🤖 Generated with Claude Code

Second leaf conversion. Drops write-security.ts from the singleton
importer set (32 → 31). Stacked on PR #19 until it merges.

- src/services/write-security.ts: dropped `import { config }`. Both
  exported functions now take config explicitly:
    - assessWriteSecurity(content, sourceSite, WriteSecurityAssessConfig)
      — reads trustScoringEnabled, trustScoreMinThreshold.
    - recordRejectedWrite(userId, content, sourceSite, decision,
      WriteSecurityRecordConfig, lessons?) — reads auditLoggingEnabled,
      lessonsEnabled, trustScoreMinThreshold (the last is used to build
      the `trust:below-threshold` audit payload, which previously read
      the singleton at emit time).
  Two new exported config interfaces (Pick-style) keep the contract
  narrow; IngestRuntimeConfig satisfies both structurally.
- src/services/memory-ingest.ts:143 + src/services/ingest-fact-
  pipeline.ts:84/130/168/87/170: all 6 call sites thread deps.config.
  No signature ripple — every caller already had deps in scope.
- src/services/memory-service-types.ts: IngestRuntimeConfig gains
  trustScoringEnabled + trustScoreMinThreshold so deps.config satisfies
  both new config interfaces structurally.
- src/services/__tests__/write-security.test.ts: stopped importing and
  mutating the runtime config singleton; builds its own config object
  per test instead. Cleaner — the tests are now pure unit tests with
  explicit inputs.
- src/__tests__/config-singleton-audit.test.ts: MAX_SINGLETON_IMPORTS
  ratcheted 32 → 31.

963/963 tests pass. tsc --noEmit clean. fallow --no-cache 0 above
threshold.

Plan: phase7-v1-parity item 3d. Three leaves remain: cost-telemetry.ts,
embedding.ts, llm.ts.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ethanj
Copy link
Copy Markdown
Contributor Author

ethanj commented Apr 18, 2026

Superseded — bundling all 3d leaves (consensus-extraction + write-security + cost-telemetry + embedding + llm) into a single PR per updated review direction.

@ethanj ethanj closed this Apr 18, 2026
@ethanj ethanj deleted the phase7-3d-write-security branch April 20, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant